﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Csla.Xaml;
using Accounting.Library;
using System.Windows.Data;
using BusinessConfiguration;

namespace csla4Skeleton.UI.SL.HeThong.HT_ThongTinCongTy
{
    public class HT_ThongTinCongTy_ListViewModel : ViewModel<HT_ThongTinCongTyList>
    {
        public event EventHandler LoadCompleted;
        public HT_ThongTinCongTy_ListViewModel(string mode)
        {
            BeginRefresh("GetHT_ThongTinCongTyList", mode);
        }

        public void GetHT_ThongTinCongTy_ListViewModel(string mode)
        {
            BeginRefresh("GetHT_ThongTinCongTyList", mode);
        }

        public static readonly DependencyProperty SelectedItemProperty =
          DependencyProperty.Register("SelectedItem", typeof(HT_ThongTinCongTyInfo), typeof(HT_ThongTinCongTy_ListViewModel), null);
        public HT_ThongTinCongTyInfo SelectedItem
        {
            get { return (HT_ThongTinCongTyInfo)GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }
        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
               
                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }
        public void DeleteHT_ThongTinCongTy(object sender, ExecuteEventArgs e)
        {
            if (e.MethodParameter != null)
            {
                //cast parameter
                string parameter = e.MethodParameter.ToString();
                this.IsBusy = true;
                Accounting.Library.HT_ThongTinCongTy.DeleteHT_ThongTinCongTy(int.Parse(parameter), (o, ex) =>
                {
                    BeginRefresh("GetHT_ThongTinCongTyList", BusinessConfiguration.Configuration.GridViewFetchMode);
                });
                this.IsBusy = false;
            }
        }
    }
}






